********************************************************************************
***APPENDIX
********************************************************************************



********************************************************************************
**Descriptive Stats

cd "C:\Users\Shea\Dropbox\Slantchev Revised\Empirical Work\Data\Analysis"
use "wardefaultJCR.dta", clear


lab var e2 "Years  since Default$^2$"
lab var e3 "Years  since Default$^3$"
lab var w2 "Years  since War$^2$"
lab var w3 "Years  since War$^3$"
lab var pdcap  "$\Delta$ Military Capabilities"
lab var war "In War"
lab var edef_rate2 "Default Rate (20 yrs)"
lab var data "Default Data" 
lab var currencycrisisbi "Currency Crisis"
lab var win "Won War"
lab var lndebtGDP "ln(Debt-to-GDP)"
lab var en_pc "Energy Per Cap"
lab var en_gro "Energy Growth"
lab var madgdppc  "GDP Per Cap (Maddison)"
lab var madgrowth "GDP Growth (Maddison)"
lab var definf "Default or Inflation Crisis"
lab var rexternal "External Default"
lab var lncap "Capabilities"

sutex rexternal edef_rate win war data  irst_pc irst_gr  lnupop wyrs  polity2 ukus data_region ///
 lncap   inflationcrisisbi ukus edef_rate wyrs w2 w3 rival issues numgps ukus eyrs e2 e3   ///
edef_rate2 definf  currencycrisisbi  lndebtGDP  en_pc  en_gro  madgdppc madgrowth    ///
, minmax labels




**State Death

list ccode year if rextdummy==1 & (allexit==1 | l.allexit==1) 


********************************************************************************
**Alternative Cross Tabs Sepcifications

use "wardefaultJCR.dta", clear

lab var edef2 "Default"
lab var win "War Outcome"
label define edef2 0 "No Default" 1 "Default"
label define win 0 "Lose" 1 "Win"

xtset ccode year



tab edef5 win , chi2 r co //Cross tabs for default 5 yrs after a war
tabout  edef5 win using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)  


capture drop wld3
gen wld3 = 1 if wld2==2 // Winners
replace wld3 = 0 if wld2== 1 // Losers
replace wld3 = -1 if wld2== -1 // Draw

tab edef2 wld3, chi2 r co //Cross Tabs with Draws
tabout  edef2 wld3 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)  

tab edef5 wld3, chi2 r co //Cross Tabs with Draws for Default after 5 years


tab def2 win , chi2 r co //All types of default
tabout  def2 win using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)  

**Targeting or Initiating Matters? No
tab edef2 win if init==1 , chi2 r co
tabout  edef2 win if init==1 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)  
tab edef2 win if target==1 , chi2 r co
tabout  edef2 win if target==1 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)  

tab edef2 win if joiner==1 , chi2 r co

**Cross tabs for Longer Wars
tab edef2 win if length>=2, chi2 r co
tabout edef2 win if length>=2 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)

sort larger_war_id year
by  larger_war_id year: egen war_parts = count(larger_war_id)

tab edef2 win if war_parts>2, chi2 r co
tabout edef2 win if war_parts>2 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)

tab edef2 win if war_parts>5, chi2 r co


tab edef2 win if batdeath>=10000, chi2 r co
tabout edef2 win if batdeath>=10000 using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)

tab edef2 win if batdeath>=100000, chi2 r co


tab definf2 win , chi2 r co
tabout definf2 win  using table1.txt, replace  cells(freq col) layout(rb)  style(tex) ///
format(0 1)

********************************************************************************
**
use "wardefaultJCR.dta", clear




*Selection stage (DV = Does state have default data (0,1); main IV = data_region  = % of states in state's region with data)

probit data  irst_pc irst_gr lnupop wyrs  polity2 ukus data_region, cluster(ccode) 
estimates store sel2


estout sel2, cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order() drop() ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")


 
 
 
 *********************************************************************
 
** Alternative Selection model specs. (Table 3 in Manuscript)
*

*Replicating model 2 with FIML 
heckprob war l.edef_rate polity2 lncap wyrs w2 w3, sel(data=irst_pc irst_gr lnupop wyrs  polity2 ukus data_region)
estimates store a1

*Replicating model 2 with FIML and keeping covariates same in each stage
heckprob war l.edef_rate polity2 lncap wyrs ukus w2 w3, sel(data= polity2 lncap wyrs w2 w3 ukus   data_region)
estimates store a2


*Replicating model 3 with FIML
 heckprob war l.edef_rate polity2 lncap   inflationcrisisbi lnupop ///
  ukus  wyrs w2 w3 rival issues numgps, sel(data=irst_pc irst_gr lnupop wyrs  polity2 ukus data_region)
   estimates store a3

*Replicating model 2 with FIML and keeping covariates same in each stage
heckprob war l.edef_rate polity2 lncap   inflationcrisisbi lnupop ///
  ukus  wyrs w2 w3 rival issues numgps, sel(data=  polity2 lncap   inflationcrisisbi lnupop ///
  ukus  wyrs w2 w3 rival issues numgps  data_region)
  estimates store a4

  estout a1 a2 a3 a4, cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order() drop() ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")
  
  
********************************************************************************
**Alternative Default Rate 
capture drop p1 mills
predict p1, xb

estimates store sel2
gen mills = exp(-.5*p1^2)/(sqrt(2*_pi)*normprob(p1))


probit war l.edef_rate2 polity2 lncap   inflationcrisisbi lnupop ///
  ukus  wyrs w2 w3 rival issues numgps mills, cluster(ccode) robust 
estimates store out3

probit war l.eyrs polity2 lncap  inflationcrisisbi lnupop ///
  ukus  wyrs w2 w3 rival issues numgps mills, cluster(ccode) robust 
estimates store out4

lab var edef_rate2 "Default Rate (20 yrs)"
lab var lncap "Capabilities"
lab var mills "Mill's Inverse Ratio"

     estout  out3 out4  , cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.05 ) ///
	eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order(L.edef_rate2 L.eyrs polity2 lncap wyrs  inflationcrisisbi lnupop ///
  ukus rival issues numgps mills) drop(w2 w3) ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")



********************************************************************************
**Alterntive GDP per cap

 //////Alterntive GDP per cap measures////////////
probit data  en_pc  en_gro  lnupop wyrs2 polity2 ukus data_region , cluster(ccode)
estimates store sel2

capture drop p1
capture drop mills 
capture drop pred_fail 
predict p1, xb


estimates store msel
gen mills = exp(-.5*p1^2)/(sqrt(2*_pi)*normprob(p1))

probit war l.edef_rate polity2 lncap   ///
  wyrs w2 w3  mills, cluster(ccode) robust 
estimates store out1


 //////Alterntive GDP per cap measures////////////
probit data  madgdppc madgrowth lnupop wyrs2 polity2 ukus data_region , cluster(ccode)
estimates store sel3

capture drop p1
capture drop mills 
capture drop pred_fail 
predict p1, xb


estimates store msel
gen mills = exp(-.5*p1^2)/(sqrt(2*_pi)*normprob(p1))


probit war l.edef_rate polity2 lncap   ///
  wyrs w2 w3  mills, cluster(ccode) robust 
estimates store out2

 
lab var lncap "Capabilities" 


estout  sel2 out1 sel3 out2, cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order(L.edef_rate en_pc  en_gro madgdppc madgrowth polity2 ) drop() ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")



***************************************************************************************************
**Pr (DEfault) and Pr (Default Onset) models

probit rexternal eyrs irst_pc irst_gr wyrs lnupop polity2  ///
  ukus  e2 e3  reg_* , cluster(ccode)
estimates store pred1

btscs rextdummy year ccode, g(eeyrs)

gen ee2 = (eeyrs*eeyrs)/1000
gen ee3 = (eeyrs*eeyrs*eeyrs)/1000000



replace rextdummy=. if rextdummy==0&rexternal==1
probit rextdummy  eeyrs irst_pc irst_gr wyrs lnupop polity2   ///
  ukus  ee2 ee3  reg_* , cluster(ccode) 
estimates store pred2

lab var eeyrs "Years since Default Onset

estout  pred1 pred2, cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order(eyrs eeyrs) drop(e2 e3 ee2 ee3 reg_*) ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")


*********************************************************************
**Selection into Treatment Robustness check
probit rexternal  irst_pc irst_gr  lnupop wyrs2 polity2 inflationcrisisbi ukus default_region, cluster(ccode)
estimates store sel4
capture drop p2
capture drop mills
predict p2, xb


gen mills = exp(-.5*p2^2)/(sqrt(2*_pi)*normprob(p2))

probit war l.edef_rate polity2 lncap   ///
  wyrs w2 w3  mills, cluster(ccode) robust 
estimates store out1

lab var mills "Mills Ratio"
lab var default_region "Regional Default"

estout  sel4 out1 , cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order(L.edef_rate  irst_pc irst_gr polity2  inflationcrisisbi eyrs) drop(w2 w3 ) ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")


***********************************************************************
***Sartori's (2003) Selection Estimator

**
use "wardefaultJCR.dta", clear

gen ledef_rate = l.edef_rate

gen sartdv = 0 if  data  ==0
replace sartdv = 1 if  data  ==1 & war==0
replace sartdv = 2 if  data  ==1 & war==1

set more off
 sartsel sartdv ledef_rate polity2 lncap wyrs w2 w3, corr(-1)
estimates store sat1

lab var ledef_rate "Default Rate"

 
estout  sat1 , unstack cells(b(star fmt(%9.3f)) se(par fmt(%9.2f))) starlevels(* 0.1 ** 0.05 *** 0.01) ///
eqlab("/lnsig2u" "ln($\sigma^2_u$)", none) ///
stats( ll aic N, fmt(%9.1f %9.1f %9.0f) labels("Log-Likelihood" "AIC") star)  style(tex) ///
legend label collabels(none) varlabels(_cons Constant) order(ledef_rate) drop(w2 w3 ) ///
mlabels ("Model 1" "Model 2" "Model 3" "Model 4") ///
title("")



